<?php

/**
 * This is the model class for table "package".
 *
 * The followings are the available columns in table 'package':
 * @property string $package_id
 * @property string $name
 * @property float $price
 * @property float $view_vedio_price
 * @property float $first_up_price
 * @property float $second_up_price
 * @property integer $create_by
 * @property string $create_date
 * @property integer $update_by
 * @property string $update_date
 * @property float $matching_limit
 * @property float $point
 * 
 * * The followings are the available model relations:
 * @property Resources $resourcesList
 * @property Member $memberList
 */
class Package extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'package';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('price, view_vedio_price, first_up_price, second_up_price, create_by, update_by, matching_limit, point', 'numerical'),
			array('name, create_date, update_date', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('package_id, price, view_vedio_price, first_up_price, second_up_price, create_by, create_date, update_by, update_date', 'safe', 'on'=>'search'),
		);
	}

	/** 
	 * @return array relational rules.
	 */
	public function relations()
	{
            return array(
                'resourcesList' => array(self::HAS_MANY, 'Resources', 'package_id'),
                'memberList' => array(self::HAS_MANY, 'Member', 'member_id'),
            );
        }

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'package_id' => 'Package',
			'name' => 'Package Name',
			'price' => 'Price',
			'view_vedio_price' => 'View Vedio Price',
			'first_up_price' => 'First Up Price',
			'second_up_price' => 'Second Up Price',
			'create_by' => 'Create By',
			'create_date' => 'Create Date',
			'update_by' => 'Update By',
			'update_date' => 'Update Date',
			'matching_limit' => 'Matching Limit',
			'point' => 'Matching Point',
		);
	}
 
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('package_id',$this->package_id,true);
		$criteria->compare('price',$this->price);
		$criteria->compare('view_vedio_price',$this->view_vedio_price);
		$criteria->compare('first_up_price',$this->first_up_price);
		$criteria->compare('second_up_price',$this->second_up_price);
		$criteria->compare('create_by',$this->create_by);
		$criteria->compare('create_date',$this->create_date,true);
		$criteria->compare('update_by',$this->update_by);
		$criteria->compare('update_date',$this->update_date,true);
                $criteria->compare('matching_limit',$this->matching_limit);
                $criteria->compare('point',$this->point);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        public function getPackageLIst(){
            return CHtml::listData($this->findAll(), 'id', 'name');
        }

        /**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Package the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
